// License: http://www.codeplex.com/entlibcontrib/Project/License.aspx
// Author: Randy

using System;

using Microsoft.Practices.ObjectBuilder;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;

using Microsoft.Practices.EnterpriseLibrary.Logging.Formatters;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

using EntLibContrib.Logging.Formatters;

namespace EntLibContrib.Logging.Configuration
{
    /// <summary>
    /// Represents the configuration settings for a custom template text formatter.
    /// </summary>
    [Assembler(typeof(TemplateTextFormatterAssembler))]
    public class TemplateTextFormatterData : TextFormatterData, ITemplateTextFormatterData
    {
    }

    /// <summary>
    /// This type supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
    /// Represents the process to build a <see cref="TemplateTextFormatter"/> described by a <see cref="TemplateTextFormatterData"/> configuration object.
    /// </summary>
    /// <remarks>This type is linked to the <see cref="TemplateTextFormatterData"/> type and it is used by the <see cref="LogFormatterCustomFactory"/> 
    /// to build the specific <see cref="ILogFormatter"/> object represented by the configuration object.
    /// </remarks>
    public class TemplateTextFormatterAssembler : IAssembler<ILogFormatter, FormatterData>
    {
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="TemplateTextFormatter"/> based on an instance of <see cref="TemplateTextFormatterData"/>.
        /// </summary>
        /// <seealso cref="LogFormatterCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="TemplateTextFormatterData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="TemplateTextFormatter"/>.</returns>
        public ILogFormatter Assemble(IBuilderContext context, FormatterData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            TemplateTextFormatterData castedObjectConfiguration = (TemplateTextFormatterData)objectConfiguration;

            ILogFormatter createdObject = new TemplateTextFormatter(castedObjectConfiguration.Template);

            return createdObject;
        }
    }
}
